package com.idanchuang.count.controller;

import com.idanchuang.component.base.JsonResult;
import com.idanchuang.count.core.annotation.UserCountUpdate;
import com.idanchuang.count.core.constant.UserCountEventTypeEnum;
import com.idanchuang.count.service.MsgUnreadCountService;
import com.idanchuang.user.count.service.api.client.MsgUnreadCountClient;
import com.idanchuang.user.count.service.api.request.command.read.AddSysMsgCommand;
import com.idanchuang.user.count.service.api.request.command.read.AddUserMsgCommand;
import com.idanchuang.user.count.service.api.request.command.read.BatchAddUserMsgCommand;
import com.idanchuang.user.count.service.api.request.command.read.RemoveSysMsgCommand;
import com.idanchuang.user.count.service.api.request.command.read.RemoveUserMsgCommand;
import com.idanchuang.user.count.service.api.request.command.read.UserMsgAllReadCommand;
import com.idanchuang.user.count.service.api.request.query.read.BatchUserUnreadMsgCountQuery;
import com.idanchuang.user.count.service.api.request.query.read.UserMsgIfReadBatchQuery;
import com.idanchuang.user.count.service.api.request.query.read.UserUnreadMsgCountQuery;
import com.idanchuang.user.count.service.api.response.BatchUserSceneCountDTO;
import com.idanchuang.user.count.service.api.response.UserSceneCountDTO;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Richard_yyf
 * @version 1.0 2021/7/6
 */
@RestController
public class MsgUnreadCountController implements MsgUnreadCountClient {

    @Resource
    private ParamsChecker paramsChecker;

    @Resource
    private MsgUnreadCountService msgUnreadCountService;

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.UserMsgAllRead)
    public JsonResult<Void> readAll(UserMsgAllReadCommand readCommand) {
        msgUnreadCountService.readAll(readCommand);
        return JsonResult.OK;
    }

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.AddUserMsg)
    public JsonResult<Void> addUserMsg(AddUserMsgCommand addUserMsgCommand) {
        msgUnreadCountService.addUserMsg(addUserMsgCommand);
        return JsonResult.OK;
    }

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.BatchAddUserMsg)
    public JsonResult<Void> batchAddUserMsg(BatchAddUserMsgCommand batchAddUserMsgCommand) {
        paramsChecker.checkMsgAddBatchSize(batchAddUserMsgCommand.getUserCodeList().size());
        msgUnreadCountService.batchAddUserMsg(batchAddUserMsgCommand);
        return JsonResult.OK;
    }

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.AddSysMsg)
    public JsonResult<Void> addSysMsg(AddSysMsgCommand addSysMsgCommand) {
        msgUnreadCountService.addSysMsg(addSysMsgCommand);
        return JsonResult.OK;
    }

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.RemoveSysMsg)
    public JsonResult<Void> removeSysMsg(RemoveSysMsgCommand removeSysMsgCommand) {
        msgUnreadCountService.removeSysMsg(removeSysMsgCommand);
        return JsonResult.OK;
    }

    @Override
    @UserCountUpdate(type = UserCountEventTypeEnum.RemoveUserMsg)
    public JsonResult<Void> removeUserMsg(RemoveUserMsgCommand removeUserMsgCommand) {
        msgUnreadCountService.removeUserMsg(removeUserMsgCommand);
        return JsonResult.OK;
    }

    @Override
    public JsonResult<UserSceneCountDTO> queryUnreadMsgCount(UserUnreadMsgCountQuery unreadMsgCountQuery) {
        UserSceneCountDTO sceneCountDTO = msgUnreadCountService.queryUnreadMsgCount(unreadMsgCountQuery);
        return JsonResult.success(sceneCountDTO);
    }

    @Override
    public JsonResult<BatchUserSceneCountDTO> batchQueryUnreadMsgCount(BatchUserUnreadMsgCountQuery batchUserUnreadMsgCountQuery) {
        BatchUserSceneCountDTO batchUserSceneCountDTO = msgUnreadCountService.batchQueryUnreadMsgCount(batchUserUnreadMsgCountQuery);
        return JsonResult.success(batchUserSceneCountDTO);
    }

    @Override
    public JsonResult<List<String>> batchQueryUserMsgIfRead(UserMsgIfReadBatchQuery userMsgIfReadBatchQuery) {
        List<String> unreadMsgNos = msgUnreadCountService.batchQueryUserMsgIfRead(userMsgIfReadBatchQuery);
        return JsonResult.success(unreadMsgNos);
    }

}
